package com.example.excel.ui.activity.local;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.example.excel.R;
import com.example.excel.base.BaseActivity;
import com.example.excel.base.BaseViewModel;
import com.example.excel.databinding.ActivityLocalInfoBinding;
import com.example.excel.ui.fragment.gallery.GalleryFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class LocalInfoActivity extends BaseActivity<ActivityLocalInfoBinding, BaseViewModel> implements View.OnClickListener{

    private FragmentManager mFragmentManager;
    private List<Fragment> mFragments;

    public static void start(Context context) {
        Intent intent = new Intent(context, LocalInfoActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected Class<BaseViewModel> initViewModel() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_local_info;
    }

    @Override
    protected void initView() {
        mFragmentManager = getSupportFragmentManager();
        mFragments = new ArrayList<>();
        mFragments.add(GalleryFragment.getInstance(0));
        mFragments.add(GalleryFragment.getInstance(1));
        mBinding.vp.setAdapter(new FragmentPagerAdapter(mFragmentManager, 1) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        });
        mBinding.vp.setOffscreenPageLimit(mFragments.size());

        mBinding.tvNext0.setOnClickListener(this);
        mBinding.tvNext1.setOnClickListener(this);
        mBinding.tvNext0.setBackground(getResources().getDrawable(R.drawable.shape_login_bg, null));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_next0:
                mBinding.tvNext0.setBackground(getResources().getDrawable(R.drawable.shape_login_bg, null));
                mBinding.tvNext1.setBackground(getResources().getDrawable(R.drawable.shape_login_edit_bg, null));
                mBinding.vp.setCurrentItem(0);
                break;
            case R.id.tv_next1:
                mBinding.tvNext0.setBackground(getResources().getDrawable(R.drawable.shape_login_edit_bg, null));
                mBinding.tvNext1.setBackground(getResources().getDrawable(R.drawable.shape_login_bg, null));
                mBinding.vp.setCurrentItem(1);
                break;
        }
    }
}
